/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import entities.Trace;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;

/**
 *
 * @author Eduardo
 */

public class TraceDAO extends GeneralDAO {

    public Trace searchById(EntityManager em,String id) {
        Query q = em.createQuery("SELECT object(t) FROM trace AS t "
                + "  WHERE t.idTrace = :id");
        q.setParameter("id", id);
        List<Trace> results = q.getResultList();
        if (results == null) {
            return null;  // No encontrado
        } else if (results.size() != 1) {
            return null; // No encontrado
        } else {
            return results.get(0);  // Devuelve el encontrado
        }
    }
    
    public Trace searchByNumbreCard(EntityManager em,String numbreCard) {
        Query q = em.createQuery("SELECT t FROM trace AS t "
                + "  WHERE t.numbreCard = :numbreCard");
        q.setParameter("numbreCard", numbreCard);
        List<Trace> results = q.getResultList();
        if (results == null) {
            return null;  // No encontrado
        } else if (results.size() != 1) {
            return null; // No encontrado
        } else {
            return results.get(0);  // Devuelve el encontrado
        }
    }


    public List<Trace> searchAll(EntityManager em) {
        Query q = em.createQuery("SELECT object(t) FROM trace as t");
        return q.getResultList();
    }

}